<?php
namespace Home\Controller;
use Think\Controller;
class PageController extends Controller{
	public function index(){
		//友情链接
		$friend = D('friend')->cache(true)->select();
		$this->assign('friend',$friend);
		//文章显示
		$art = D('arts');
		$aid = I('get.id');
		//关联模型
		$myArt = $art->find($aid);
		$mycomment = $art->relationGet('comments');
		$this->history($myArt);
		$this->assign('history',array_reverse(session('history')));
		$this->assign('myArt',$myArt);
		$this->assign('comment',$mycomment);
		$this->display();
	}

	//查看历史
	public function history($myArt){
		$row = session('?history')?session('history'):array();
		$g = array();
		$g['aid'] = I('get.id');
		$g['title'] = $myArt['title'];
		$g['img_path'] = $myArt['img_path'];
		$row[I('get.id')] = $g;

		if(count($row)>12){
			$key = key($row);
			unset($key);
		}
		session('history',$row);
	}
	public function addcomment(){
		$comm = D('comments');
		// dump($_POST);
		// exit();
		if($comm->add(I())){
			$this->success('留言成功','',3);
		}
	}
}